<template>
	<view class="container">
		<view class="o-plr">
			<view class="c-t75 c-tb o-ptb">电梯信息</view>
			<view class="u-b c-r-l c-bg-f o-p c-line-13">
				<view class="">
					<text class="c-ws">电梯注册代码：</text>
					{{f_opt.eleCode}}
				</view>
				<view class="">
					<text class="c-ws">安装地址：</text>
					{{f_opt.location}}
				</view>
				<view class="">
					<text class="c-ws">详细位置：</text>
					{{f_opt.locationDetail}}
				</view>
			</view>
			<view class="c-t75 c-tb o-ptb">投诉建议</view>
			<view class="c-bg-f o-mb c-r-l">
				<u-field
					v-model="name"
					label="姓名"
					placeholder="请填写姓名"
				>
				</u-field>
				<u-field
					v-model="phone"
					label="手机号"
					placeholder="请填写手机号"
					maxlength="11"
				>
				</u-field>
			</view>
			<com-textarea ref="area" :height="{height: '200rpx'}"></com-textarea>
			
			<view class="c-t75 c-tb o-ptb">上传图片</view>
			<view class="">
				<u-upload class="c-bg-f" :show-progress="false" :max-size="3 * 1024 * 1024" max-count="5" :action="action" :header="header" :file-list="fileList" ref="uUpload" ></u-upload>
			</view>
			
			<u-button type="primary" style="margin: 100rpx 0;" @click="submit()">提交</u-button>
			
		</view>
	</view>
</template>

<script>
	import comTextarea from "@/components/comtextarea.vue"
	export default {
		name: 'proposal',
		data() {
			return {
				action: 'http://192.168.1.21:88/blade-resource/oss/endpoint/put-file-attach', //后端服务器地址
				header: {
					"Blade-Auth": 'bearer ' +   uni.getStorageSync('token')
				},
				// (数组，元素为对象)，显示预置的图片。其中元素的url属性为图片路径
				fileList: [],
				f_opt:{},
				name: null,
				phone: null
			}
		},
		components:{comTextarea},
		onLoad(opt) {
			this.f_opt = JSON.parse(opt.data)
		},
		methods:{
			submit() {
				// console.log(this.$refs.area.content)
				let files = [];
				files = this.$refs.uUpload.lists.map(val => {
					if(val.progress == 100) return val.response.data.name;
				})
				if(!this.name) {
					this.$Function('请输入姓名');
					return
				};
				if(!this.$Function.MobileVer(this.phone)) {
					this.$Function('请输入正确的手机号');
					return
				};
				if(!this.$refs.area.content) {
					this.$Function('请输入投诉建议');
					return
				};
				let data = {
					userId: uni.getStorageSync('userId'),
					eleId: this.f_opt.id,
					complainName: this.name,
					complainPhone: this.phone,
					complainContent: this.$refs.area.content,
					complainImgUrl:	files.join(',')
				}
				console.log('data ==>', data)
				this.$store.dispatch('post_complainSave',data)
				.then(res => {
					console.log('res ==>', res)
					if(res.data.code == 200) {
						this.$Function.Toast(res.data.msg);
						setTimeout(() => {this.$Function.LinkTo('', 'Back')})
					}
				})
			}
		}
	}
</script>

<style>
</style>
